	
define(['vue','moment','config','common','../model/upLoadList','../model/downLoadList'],
	function(Vue,moment,config,utils,upLoadList,downLoadList){
	'use strict';

	var FundsDetailView = new Vue({
		el:'#app',
		data:{
			list:'',	
			page: 1,
			totalPage:0,
			isLoadMore:0,
			pageSize:'',
		},
		filters: {
		  moment: function (date) {
		    return moment(date).format('MM-DD');
		  }
		},
		watch:{
			list: function(to,from){
				if(to.length == 0 && this.list !== ""){
					$('.error404').show();
				}else{
					$('.error404').hide();
				}
			}
		},
		created:function(){	
			var _this=this;
			//_this.pageSize = parseInt(Math.ceil(($('body').height()-$('.headTitle').height()-$('.title').height())/43), 10);
			_this.pageSize = 30;
			var data = {
				page: _this.page,
				pageSize: _this.pageSize
			}
			upLoadList.ajax(utils.getWebUrl('transactionRecord/list'),data,function(res){
				_this.list = res.data.list;
				_this.totalPage = res.data.totalPage;

				for (var i = _this.list.length - 1; i >= 0; i--) {
					if(_this.list[i].sourceType==1){
						_this.list[i].sourceType="充值";
					}else if(_this.list[i].sourceType==2){
						_this.list[i].sourceType="享积分转换";
					}else if(_this.list[i].sourceType==3){
						_this.list[i].sourceType="升级余额奖励";
					}else if(_this.list[i].sourceType==4){
						_this.list[i].sourceType="余额转存提现";
					}else if(_this.list[i].sourceType==5){
						_this.list[i].sourceType="升级VIP";
					}
				}
			})
		},
		directives: {
		  scroll: {
		    bind: function (el, binding){
		      window.addEventListener('scroll',function() {
		       		var fnc = binding.value;   
   					fnc();
		      })
		    }
		  }
		},
		//判定事件
		methods:{
			back:function(){
				var userTypeId =utils.getData('userTypeId');
				if(userTypeId == 5){
					window.location.href='shopInfo.html';
				}else{
					
					window.location.href='userInfo.html';
				}
			},
			loadMore:function(event){

				var _this = this;

				if ((upLoadList.getScrollTop() + upLoadList.getClientHeight() >= upLoadList.getScrollHeight())&&_this.page<_this.totalPage) {
					_this.page = _this.page+1;

					var data = {
						page: _this.page,
						pageSize: _this.pageSize
					}
					
					upLoadList.ajax(utils.getWebUrl('transactionRecord/list'),data,function(res){
						for (var i = res.data.list.length - 1; i >= 0; i--) {
							if(_this.list[i].sourceType==1){
								_this.list[i].sourceType="充值";
							}else if(_this.list[i].sourceType==2){
								_this.list[i].sourceType="享积分转换";
							}else if(_this.list[i].sourceType==3){
								_this.list[i].sourceType="升级余额奖励";
							}else if(_this.list[i].sourceType==4){
								_this.list[i].sourceType="余额转存提现";
							}else if(_this.list[i].sourceType==5){
								_this.list[i].sourceType="升级VIP";
							}
						}	
						_this.list = _this.list.concat(res.data.list);
						_this.totalPage = res.data.totalPage;

					})
		        }
			},
			Start:function(event){

				var touch = event.targetTouches[0];
				this.start = touch.pageY;

			},

			Move:function(event){
				var slideDown1 = $('#pullDown1');
				var touch = event.targetTouches[0];
				this.end = (this.start - touch.pageY);
				//下滑才执行操作 
                if(this.end < 0){
                	
                	slideDown1.text('下拉刷新↓');
	        		slideDown1.show();
	        		slideDown1[0].style.height =  (parseInt("0px")-this.end) + "px";
	        		if(this.end < -48){
	        			/*slideDown1.hide(); 
	        			downLoadList.slideDownStep1(this.end);*/
	        			slideDown1.text('松手开始更新↑')
	        		}
                }else{
                	slideDown1.hide();
                }
			},

			End:function(event){
				var _this = this;
				var slideDown1 = $('#pullDown1');
				if(this.end >0){  
					slideDown1.hide();
	            }else{ 

	                if(this.end < -48 && document.body.scrollTop == 0){
	                	var slideDown1 = $('#pullDown1');
	                	var slideDown2 = $('#pullDown2');
						//$('.pullDownLabel').text("下拉刷新...");
						slideDown1.hide();
				        slideDown2.show();

	                	downLoadList.slideDownStep2(); 
		                //刷新成功则 
		                //模拟刷新成功进入第三步

		                // setTimeout(function(){  		
		                //     downLoadList.slideDownStep3();
		                // },2000)
		                //请求数据
		                _this.page = 1;
		                //_this.list = '';
		                var data = {
							page: _this.page,
							pageSize: _this.pageSize
						}
						utils.ajax(utils.getWebUrl('transactionRecord/list'),data,
							'POST'
							,function(res){
		                		_this.list = res.data.list;
								_this.totalPage = res.data.totalPage;
								//积分来源1直接消费2消费推荐3销售4销售推荐5升级6激励E积分7转化成享积分8升级推荐
								for (var i = _this.list.length - 1; i >= 0; i--) {
									if(_this.list[i].sourceType==1){
										_this.list[i].sourceType="充值";
									}else if(_this.list[i].sourceType==2){
										_this.list[i].sourceType="享积分转换";
									}else if(_this.list[i].sourceType==3){
										_this.list[i].sourceType="升级余额奖励";
									}else if(_this.list[i].sourceType==4){
										_this.list[i].sourceType="余额转存提现";
									}else if(_this.list[i].sourceType==5){
										_this.list[i].sourceType="升级VIP";
									}
								}   
						},function(){
							//_this.finishUpload = false;
						},function(){
							downLoadList.slideDownStep3();
							//_this.finishUpload = true;
						})
		                
	                }else{
	                	var slideDown1 = $('#pullDown1');
		        		slideDown1.hide();
	                }
	            }
			}
		}
		
	});


	return FundsDetailView
});
